package com.kvest.pendingintenttest;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.kvest.pendingintenttest.service.HiddenService;
import com.kvest.pendingintenttest.service.MainService;

public class PendingIntentTestActivity extends Activity {
    public static final String PENDING_INTENT_PARAMETER = "pi_param";
    public static final String TIME_PARAMETER = "time_param";

    private static final int REQUEST_CODE = 7;
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    public void onForResultClick(View view) {
        PendingIntent pi = createPendingResult(REQUEST_CODE, null, 0);

        Intent intent = new Intent(this,  MainService.class);
        intent.putExtra(TIME_PARAMETER, 3000);
        intent.putExtra(PENDING_INTENT_PARAMETER, pi);

        startService(intent);
    }

    public void onForStartActivityClick(View view) {
        Intent intent = new Intent(this, HiddenActivity.class);
        intent.putExtra("TEST", "this is extra string for HiddenActivity");
        PendingIntent pi = PendingIntent.getActivity(this, 7, intent, 0);

        Intent serviceIntent = new Intent(this,  MainService.class);
        serviceIntent.putExtra(TIME_PARAMETER, 3000);
        serviceIntent.putExtra(PENDING_INTENT_PARAMETER, pi);
        startService(serviceIntent);
    }

    public void onForStartServiceClick(View view) {
        Intent intent = new Intent(this, HiddenService.class);
        intent.putExtra("TEST", "this is extra string for HiddenActivity");
        PendingIntent pi = PendingIntent.getService(this, 7, intent, 0);

        Intent serviceIntent = new Intent(this,  MainService.class);
        serviceIntent.putExtra(TIME_PARAMETER, 3000);
        serviceIntent.putExtra(PENDING_INTENT_PARAMETER, pi);
        startService(serviceIntent);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.d("KVEST_TAG", "onActivityResult=[requestCode" + requestCode + ", resultCode=" + resultCode + ", action=" + (data == null ? "no data" : data.getAction()));
    }
}
